﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;

void test() {
	int a = 1;
	cout << ++a << endl; // 2
	cout << a++ << endl; // 2
	cout << a << endl; // 3
}

class Maker {
	friend ostream & operator<<(ostream &os, const Maker &m);
public:
	Maker(int a) {
		this->a = a;
	}
	// 重载前置加加
	Maker & operator++() {
		++a;
		return *this;
	}
	// 重载后置加加，返回临时对象  
	Maker operator++(int) { // 占位参数，必须是int 
		Maker tmp(*this);
		++this->a;
		return tmp; 
	}
private:
	int a; 
};

ostream & operator<<(ostream &os, const Maker &m) {
	os << "{this=" << &m << ",a=" << m.a << "}";
	return os;
}


void test01() {
	Maker m(10);
	cout << m << endl;
}

void test02() {
	Maker m(30);
	cout << m << endl; // {this=00DFF810,a=30} 
	cout << ++m << endl; // {this=00DFF810,a=31} 
	cout << m++ << endl; // {this=00DFF744,a=31} 
	cout << m << endl; // {this=00DFF810,a=32} 
}

int main()
{

	// test(); 
	// test01(); 
	test02(); 

	system("pause");
	return EXIT_SUCCESS;
}